package com.xingchi.tornado.dict.controller;

import com.xingchi.tornado.basic.Result;
import com.xingchi.tornado.dict.model.dto.DictItemDTO;
import com.xingchi.tornado.dict.service.DictStorageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 *  前端控制器
 *
 * @author xingchi
 * @date 2024-05-20 22:34
 */
@RestController
@RequestMapping("/dict")
@Tag(name = "字典信息控制器", description = "提供系统内所有字典的查询操作")
public class DictController {

    @Autowired
    private DictStorageService dictStorageService;

   @GetMapping("/all")
   @Operation(summary = "获取系统中所有枚举", description = "获取系统中所有枚举")
   public Result<Map<String, List<DictItemDTO>>> all() {
       return Result.ok(dictStorageService.getDictCache());
   }

   @GetMapping("/group/{group}")
   @Operation(summary = "根据分组内容查询对应分组的所有分组项", description = "根据分组内容查询对应分组的所有分组项")
   public Result<List<DictItemDTO>> group(@PathVariable("group") String group) {
       return Result.ok(dictStorageService.getDictCache(group));
   }

}
